package cn.swh.guguanjia.controller;

import cn.swh.guguanjia.entity.Result;
import cn.swh.guguanjia.entity.SysOffice;
import cn.swh.guguanjia.service.SysOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

//机构管理
@RestController
@RequestMapping("/mapper/office")
public class SysOfficeController {

    @Autowired
    SysOfficeService service;

    @RequestMapping("")
    public ModelAndView index() {
        return new ModelAndView("/office/office.html");
    }

    @RequestMapping("selectAll")
    public Result selectAll() {
        SysOffice sysOffice = new SysOffice();
        sysOffice.setDelFlag("0");
        List<SysOffice> select = service.select(sysOffice);
        return new Result(select);
    }

    @RequestMapping("selectById")
    public Result selectById(long rid) {
        return new Result(true, "查询成功", service.selectById(rid));
    }

    @RequestMapping("selectPage/{pageNum}/{pageSize}")
    public Result selectPage(@PathVariable int pageNum, @PathVariable int pageSize, @RequestParam Map<String, Object> map) {
        return new Result(service.selectPage(pageNum, pageSize, map));
    }

    @RequestMapping(value = "toUpdate")
    public ModelAndView toUpdate() {
        return new ModelAndView("/office/save.html");
    }


    @RequestMapping(value = "doUpdate",method = RequestMethod.POST)
    public Result doUpdate(@RequestBody SysOffice sysOffice) {
        return new Result(service.updateByPrimaryKeySelective(sysOffice));
    }


}
